#include "report_handle.h"

static TaskHandle_t thread_report;
iot_dazzling_info_t status_dazzling_info; 

void iot_report_init()
{
    memset(&status_dazzling_info,0,sizeof(iot_dazzling_info_t));
}



void iot_report_handle()
{
    /*主场景相关*/
    if (status_dazzling_info.main_ssp != app_logic_get_ssp())
    {
        status_dazzling_info.main_ssp= app_logic_get_ssp();
        change_main_mode_handle(MAIN_MODE,status_dazzling_info.main_ssp);
    }

    /*********************场景相关相关设置******************************************************/
    if(status_dazzling_info.scene_mode != get_scene_ssp())
    {
        status_dazzling_info.scene_mode = get_scene_ssp();
        change_scene_mode_handle(SCENE_MODE,status_dazzling_info.scene_mode);
    }//场景模式子模式切换


    /*********************CW相关******************************************************************/
    if (status_dazzling_info.cw_date_config.brighness != get_cw_config_brighness())
    {
        status_dazzling_info.cw_date_config.brighness = get_cw_config_brighness();
        change_CW_brighness_handle(BRIGHNESS_CW,status_dazzling_info.cw_date_config.brighness);
    }//亮度

    if (status_dazzling_info.cw_date_config.w != get_cw_config_w())
    {
        status_dazzling_info.cw_date_config.w = get_cw_config_w();
        change_CW_level_handle(LEVEL_CW,status_dazzling_info.cw_date_config.w);
    } //色温

    /*********************分段模式相关的相关相关设置******************************************************/
    if((status_dazzling_info.part_info.len != part_info.len) || memcmp(status_dazzling_info.part_info.RGB,part_info.RGB,part_info.len*3))
    {
        status_dazzling_info.part_info.len = part_info.len;
        memcpy(status_dazzling_info.part_info.RGB,part_info.RGB,part_info.len*3);
        change_part_info_handle(PART_DATA,status_dazzling_info.part_info);
    }

    /*********************麦克风相关设置******************************************************/
    if(status_dazzling_info.micro_senst != get_senst_level()) //灵敏度
    {
        status_dazzling_info.micro_senst = get_senst_level();
        change_micro_senst_handle(MICRO_SENST,status_dazzling_info.micro_senst);
    }

    if(status_dazzling_info.spectral_mode != get_micro_ssp())  //子模式
    {
        status_dazzling_info.spectral_mode = get_micro_ssp();
        change_spectral_mode_handle(SPECTRAL_MODE,status_dazzling_info.spectral_mode);
    }
    /**********************方向设置*********************************************************/
    if (status_dazzling_info.set_Direction != get_light_diretion()) //方向设置
    {
        status_dazzling_info.set_Direction = get_light_diretion();
        change_direction_mode_handle(DIRE_MODE,status_dazzling_info.set_Direction);
    }
    
    
    report_dazzling_handle(); //上报处理函数
}

void iot_report_loop(void *pvParameters)
{
    LOG_INFO("INTO iot_report_loop\n"); 
    iot_report_init();
    while (1)
    {
        iot_report_handle();
        vTaskDelay(pdMS_TO_TICKS(IOT_REPORTE_SPEED_MS)); //延时20ms
    }
}

void task_iot_report_init()
{
    xTaskCreate(iot_report_loop,"iot_report_dazzling_loop",REPORT_LOGIC_SZIE,NULL,TASK_PROP_IOTTALK,&thread_report);
}